package cn.njxzc.examples;

import java.util.Date;

public class Exam7_3 extends Thread {
	int sleepTime;
	String name;
	int counter;

	public Exam7_3(int x, String n) {
		sleepTime = x;
		name = n;
		counter = 0;
	}

	public void run() {
		while (counter < 3) {
			try {
				counter++;
				System.out.println(name + ":"
						+ new Date(System.currentTimeMillis()));
				Thread.sleep(sleepTime);
			} catch (InterruptedException e) {
				System.out.println(e);
			}
		}
	}

	public static void main(String[] args) {
		Exam7_3 t1 = new Exam7_3(1000, "Thread1");
		t1.start();
		Exam7_3 t2 = new Exam7_3(2000, "Thread2");
		t2.start();
		System.out.println(t1.isAlive() ? "Thread1 is running"
				: "Thread1 is terminated");
		System.out.println(t2.isAlive() ? "Thread2 is running"
				: "Thread2 is terminated");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			System.out.println(e);
		}
		System.out.println(t1.isAlive() ? "Thread1 is running"
				: "Thread1 is terminated");
		System.out.println(t2.isAlive() ? "Thread2 is running"
				: "Thread2 is terminated");
	}
}
